home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / VIEW / APTCMN.CPP next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  2.0 KB  |  92 lines

  1. // the implementation of class CAptCommonDialog
  2. // Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include "../stdafx.h"
  5.  
  6. #include "../kbandef.h"
  7.  
  8. #include "aptcmn.h"
  9.  
  10. BEGIN_MESSAGE_MAP(CAptCommonDialog, CDialog)
  11.   ON_LBN_DBLCLK   (IDC_EXISTING, OnDblClk   )
  12.   ON_LBN_SELCHANGE(IDC_EXISTING, OnSelChange)
  13.   ON_BN_CLICKED   (IDC_PURGE   , OnPurge    )
  14. END_MESSAGE_MAP()
  15.  
  16. CAptCommonDialog::CAptCommonDialog(
  17.   CWnd*            pParentWnd,
  18.   uint             nID,
  19.   const APT_TABLE& apt_table,
  20.   const APT_TABLE& apt_table_purged,
  21.   const APERTURE&  prev
  22. )
  23.   : CDialog(nID, pParentWnd),
  24.     m_apt_table       (apt_table),
  25.     m_apt_table_purged(apt_table_purged),
  26.     m_prev            (prev)
  27. {
  28. }
  29.  
  30. CListBox& CAptCommonDialog::ctlExisting(void)
  31. {
  32.   return *(CListBox*)GetDlgItem(IDC_EXISTING);
  33. }
  34.  
  35. void CAptCommonDialog::SetTextInt(CEdit* pEdit, int value)
  36. {
  37.   char str[50];
  38.   sprintf(str, "%d", value);
  39.   pEdit->SetWindowText(str);
  40. }
  41.  
  42. void CAptCommonDialog::OnSelChange(void)
  43. {
  44.   int sel = ctlExisting().GetCurSel();
  45.   SetAll(m_apt_table[sel]);
  46. }
  47.  
  48. void CAptCommonDialog::OnDblClk(void)
  49. {
  50.   OnSelChange();
  51.   OnOK();
  52. }
  53.  
  54. int CAptCommonDialog::unit_change_micron2kban(int micron)
  55. {
  56.   return micron * DIS_MICRON;
  57. }
  58.  
  59. void CAptCommonDialog::DeleteAllItems(void)
  60. {
  61.   for(uint i = 0; i < m_apt_table.size(); i++) {
  62.     ctlExisting().DeleteString(0);
  63.   }
  64. }
  65.  
  66. void CAptCommonDialog::RegisterAllItems(void)
  67. {
  68.   for(uint i = 0; i < m_apt_table.size(); i++) {
  69.     const APERTURE& current = m_apt_table[i];
  70.     AddAperture(current);
  71.     if(current == m_prev) {
  72.       m_index = i;
  73.     }
  74.   }
  75. }
  76.  
  77. void CAptCommonDialog::OnPurge(void)
  78. {
  79.   if(m_apt_table_purged.size() == 0) {
  80.     MessageBeep(0);
  81.   } else {
  82.     DeleteAllItems();
  83.     m_index = 0;
  84.     m_apt_table = m_apt_table_purged;
  85.     RegisterAllItems();
  86.     if(m_apt_table.size() != 0) {
  87.       SetAll(m_apt_table[m_index]);
  88.       ctlExisting().SetCurSel(m_index);
  89.     }
  90.   }
  91. }
  92.